<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include  file="/WEB-INF/oss/base/common/variable.jsp"%>
    <%@ include  file="/WEB-INF/oss/base/common/resource_lib.jsp"%>
    <%@ include  file="/WEB-INF/oss/base/common/variable_js.jsp"%>
</head>
<script src="../../../page/common/util.js"></script>
<script type="text/javascript">
    function value_function(data,seq){
        // return  "<button onclick='t_modify(this,"+data.id+")' class='button button-small border-blue'>编辑</button> "+
        //     "<button onclick='t_delete(this,"+data.id+")' class='button button-small border-red'>删除</button> "+
        //     "<button onclick='t_add(this,"+data.id+")' class='button button-small border-blue'>增加报警量</button> ";
    }

    function addUser(){
        $("#addUser input,#addUser select").val("");
        openWindow("新增用户","#addUser","400px");
    }

    function t_add(a,b){
        $("#addInfo input").val("0");
        $(".user_id").val(b);
        openWindow("新增短信或者语音数量","#addInfo","400px");
    }

    function t_modify(obj,id){
        writeVal("init-id",id);
        openWindow("编辑用户信息","#modifyUser","400px");
        manual_init_detail_get($("#detail_get"));
    }

    function t_generate(obj,id){
        openWindow("项目授权",".grant_auth","400px");

        $(".saveScene").attr("tag",id);
        postAjax(localUrl+"/page/relation/scene/user?paged=1&pageSize=100", {user_id:'${user.id}' },function(data){
            if( isOK(data) ){
                console.log(data);
                $(".scene-list").empty();
                for(var i=0;i<data.data.data.length;i++){
                    $(".scene-list").append('<div class="scene-style" onclick="selectedScene(this);" tag="'+ data.data.data[i].scene_id +'">'+' <span class="ml-10">  '+data.data.data[i].name+'</span>'+'</div>');
                }
                // 获取该用户已有的授权信息
                postAjax(localUrl+"/page/relation/scene/user?paged=1&pageSize=100", {user_id:id},function(data){
                    if( isOK(data) ){
                        for(var i=0;i<data.data.data.length;i++){
                            $("div.scene-style[tag='"+data.data.data[i].scene_id  +"']").addClass("active");
                        }
                    }
                })
            }else{
                tip(data.statusMsg);
            }
        })
    }

    function selectedScene(obj){
        if( $(obj).hasClass("active") ){
            $(obj).removeClass("active");
        }else{
            $(obj).addClass("active");
        }
    }

    function t_delete(obj,id){
        lcomfirm('是否确定删除该用户？',function(){
            commonAjax("DELETE",localUrl+"/user/info?id="+id, "",function(data){
                if(isOK(data)){
                    tip("删除成功");
                    setTimeout(function(){
                        closeAll();
                        $("#init-table").tableAdaptor();
                    },1000);
                }else{
                    tip(data.statusMsg);
                }
            });
        });
    }

    function sunccessReturn(data){
        if(data.status == status_code.OK){
            tip("成功");
            setTimeout(function(){
                closeAll();
                $("#init-table").tableAdaptor();
            },1000)
        }else{
            tip(data.statusMsg);
        }
    }
    function selectedAll(obj){
        if( $(obj).hasClass("active") ){
            $(obj).removeClass("active");
            $(obj).find("input").attr("checked",false);
            $(".scene-style").removeClass("active");
        }else{
            $(obj).addClass("active");
            $(obj).find("input").attr("checked",true);
            $(".scene-style").addClass("active");
        }
    }
    function editNum(){
        alert(1) ;
    }
    $(document).delegate(".limiter","click",function(){
        layer.tips($(this).attr("tag") , this, {
            tips: [1, '#4682B4']
        });
    })
    $(function(){
        $(".saveScene").click(function(){
            var obj ='';
            for(var i=0;i<$(".scene-style.active").length;i++){
                obj += ","+$(".scene-style.active").eq(i).attr("tag");
            }
            // 保存更新数据
            postAjax(localUrl+"/relation/scene/user", {aid:'${user.id}',user_id:$(".saveScene").attr("tag"),ids:obj.substring(1) },function(data){
                if( isOK(data) ){
                    tip("保存成功");
                    setTimeout(function(){
                        closeAll();
                    }, 1000);
                }else{
                    tip(data.statusMsg);
                }
            })
        })
    });
    function uploadFile() {
        var input = document.getElementById('fileInput');
        var file = input.files[0];

        var formData = new FormData();
        formData.append('file', file);
        formData.append("category", "file");
        formData.append("type", file.type);
        formData.append("name", file.name);
        formData.append("size", file.size);
        formData.append("id"," WU_FILE_O")
        formData.append("lastModifiedDate", file.lastModifiedDate);
        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/service/upload.json', true);

        xhr.onload = function() {
            if (this.status == 200) {
                var response = this.responseText;
                // alert(response);
                addFile(response)
                // tip("上传成功");
            } else {
                tip("上传失败");
            }
        };

        xhr.send(formData);
    }

    function  addFile(response){
        console.log(response)
        var data = {
            name:'上传文件',
            dis_img:"/res"+JSON.parse(response).data,
            moudle_type: 4
        }

        commonAjax("POST","http://192.168.1.11:8080/service/moudle/visual", data,function(e){
            if(e.status == 2){

                tip("上传成功");
            }else{
                // app.$message.error(e.statusMsg);
                tip("上传失败");
            }
        });
        //http://10.10.1.28:8080/service/moudle/visual
    }

</script>
<style type="text/css">
    .grant_auth{
        padding: 20px;
    }
    .scene-style{
        padding-left: 30px;
        height: 30px;
        line-height: 30px;
        background: #d9d9d9;
        color: #333;
        margin: 2px 0;
        border-radius: 3px;
        cursor: pointer;
    }
    .scene-style.active{
        background: #3499da;
        color: white;
    }
    .limiter{
        cursor: pointer;
    }
    .input-auto{
        width: 150px;
        display: inline;
    }
</style>
<body>
<div class="app-container">
    <div class="search-condition" type-option="search_table" config-option=" 'submit':'#searchbtns',
															'table':'#init-table',
															'wait_flag':true">
        <input type-name="name" placeholder="关键字"  class="input input-auto layui-input" />
<%--        <input type-name="scene_id" class="scene_id" type="hidden" />--%>
        <button id="searchbtns" class="button ml-20 bg-sub layui-btn layui-btn-normal"><span class="icon-search"></span> 查询</button>
        <div style="display: inline-block">
            <input type="file" id="fileInput" class=" ml-20 bg-sub layui-btn layui-btn-normal">
            <button onclick="uploadFile()" class="button ml-20 bg-sub layui-btn layui-btn-normal">上传</button>
        </div>
<%--        <button onclick="addUser();" class="button ml-20 bg-sub layui-btn layui-btn-normal float-right"><span class="icon-plus"></span> 新增用户</button>--%>
    </div>

    <div style="margin-top:10px;">
        <div id="init-table" type-option="table"  config-option="url:'/page/moudle/visual',
						param:{},
						columns:[
							{'name':'序号','type':'seq','value':'seq','width':'6%'},
							{'name':'名称','value':'name',limit:10,'width':'10%'},
							{'name':'链接','value':'dis_img','width':'7%'},
							{'name':'上传时间',type:'time','value':'atime','width':'11%'},
							{'name':'操作','type':'self','value_callback':'value_function','width':'13%'}]" >
        </div>
    </div>
</div>

<div style="display:none;padding:20px;" type-option="form_submit" id="addUser"
     config-option="  url:'/user/info',
												   submit:'.add-Btn',
												   success:'sunccessReturn',
												   validate:{ 'tigger':'submit','style':'color,pop'} ">
    <div class="form-line">
        <span>用户名：</span>
        <input placeholder="用户名" validate="empty" type-name="name" class="input input-window" >
    </div>
    <div class="form-line">
        <span>密码：</span>
        <input placeholder="密码" validate="empty" type-name="password" class="input input-window" >
    </div>
    <div class="form-line">
        <span>手机号：</span>
        <input placeholder="手机号"  type-name="phone" validate="phone:请输入正确的手机格式" class="input input-window" >
    </div>
    <div class="form-line">
        <span>邮箱：</span>
        <input placeholder="邮箱"  type-name="email" validate="email:请输入正确的邮箱格式" class="input input-window" >
    </div>
    <div class="form-line">
        <span>用户类型：</span>
        <select type-name="type" validate="empty:请选择用户类型" type-option="selecter"
                config-option="'method':'GET','url':'/dictionary/6','key':'code','value':'name',
						'init_value':'请选择用户类型','type':'list' " class="input input-window" ></select>
    </div>
    <div class="form-line">
        <button class="add-Btn button ml-20 border-blue">保存</button>
        <button onclick="closeAll();" class="button ml-10 border-red">取消</button>
    </div>
</div>

<div class="grant_auth hide">
    <div class="pointer" onclick="selectedAll(this);">
        <input type="checkbox"> <span>全选</span>
    </div>
    <div class="pt-10 mt-10 scene-list">
    </div>
    <div class="mt-10">
        <button class="saveScene button ml-20 border-blue">保存</button>
        <button onclick="closeAll();" class="button ml-10 border-red">取消</button>
    </div>
</div>

<div style="display:none;padding:20px;" type-option="form_submit" id="modifyUser"
     config-option="  url:'/user/info', method :'put',
												  submit :'.modify-Btn',
												  success:'sunccessReturn' ">
    <div id="detail_get" config-option=" url:'/user/info?id=$#init-id$' ">
        <input type="hidden" type-name="id" id="init-id" >
        <div class="form-line">
            <span>用户名：</span>
            <input placeholder="用户名" validate="empty" type-name="name" class="input input-window" >
        </div>
        <div class="form-line">
            <span>密码：</span>
            <input placeholder="密码" validate="empty" type-name="password" class="input input-window" >
        </div>
        <div class="form-line">
            <span>手机号：</span>
            <input placeholder="手机号"  type-name="phone" validate="phone:请输入正确的手机格式" class="input input-window" >
        </div>
        <div class="form-line">
            <span>邮箱：</span>
            <input placeholder="邮箱"  type-name="email" validate="email:请输入正确的邮箱格式" class="input input-window" >
        </div>
        <div class="form-line">
            <span>用户类型：</span>
            <select type-name="type" validate="empty:请选择用户类型" type-option="selecter"
                    config-option="'method':'GET','url':'/dictionary/6','key':'code','value':'name',
						'init_value':'请选择用户类型','type':'list' " class="input input-window" ></select>
        </div>
        <div class="form-line">
            <button class="modify-Btn button ml-20 border-blue">保存</button>
            <button onclick="closeAll();" class="button ml-10 border-red">取消</button>
        </div>
    </div>
</div>

<div style="display:none;padding:20px;" type-option="form_submit" id="addInfo"
     config-option="  url:'/alarm/record/update', method :'put',
												  submit :'.addinfo-Btn',
												  success:'sunccessReturn' ">
    <input type="hidden" type-name="user_id" class="user_id" >
    <div class="form-line">
        <span>新增短信量：</span>
        <input placeholder="新增短信数量" validate="empty" type="number" value="0" type-name="sms_num" class="input input-window" >
    </div>
    <div class="form-line">
        <span>新增语音量：</span>
        <input placeholder="新增语音数量" validate="empty" type="number" value="0" type-name="voice_num" class="input input-window" >
    </div>
    <div class="form-line">
        <button class="addinfo-Btn button ml-20 border-blue">保存</button>
        <button onclick="closeAll();" class="button ml-10 border-red">取消</button>
    </div>
</div>

</body>
</html>